
import { getAllSubject } from '@/api/subject'
export default {
  namespaced: true,
  state: {
    subjectList: [],
    directoryList: []
  },
  mutations: {
    setSubjectList(state, data) {
      state.subjectList = data
    },
    setDirectoryList(state, key) {
      const directory = state.subjectList.find(({ id }) => id === key)
      state.directoryList = directory ? directory.children : []
    },
    clearDirectoryList(state) {
      state.directoryList = []
    }
  },
  actions: {
    async getSubjectList(ctx) {
      const res = await getAllSubject()
      ctx.commit('setSubjectList', res)
    }
  }
}
